package com.example.rjb_shoping.service.impl;

import com.example.rjb_shoping.dao.RjbCommodityDao;
import com.example.rjb_shoping.entity.RjbAdmin;
import com.example.rjb_shoping.entity.RjbCommodity;
import com.example.rjb_shoping.query.UserQuery;
import com.example.rjb_shoping.service.RjbCommodityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (RjbCommodity)表服务实现类
 *
 * @author makejava
 * @since 2021-06-09 20:42:45
 */
@Service("rjbCommodityService")
public class RjbCommodityServiceImpl implements RjbCommodityService {
    @Resource
    private RjbCommodityDao rjbCommodityDao;

    @Override
    public RjbCommodity queryById(Integer mId) {
        return this.rjbCommodityDao.queryById(mId);
    }

    @Override
    public List<RjbCommodity> queryAllByLimit(int offset, int limit) {
        return this.rjbCommodityDao.queryAllByLimit(offset, limit);
    }

    @Override
    public PageInfo<RjbCommodity> limitList(int status, UserQuery userQuery) {
        PageHelper.startPage(userQuery.getPageNum(), userQuery.getPageSize());
        RjbCommodity rjbCommodity = new RjbCommodity();
        rjbCommodity.setMName(userQuery.getName());
        rjbCommodity.setMStatus(status);
        final List<RjbCommodity> rjbAdmins = rjbCommodityDao.queryAll(rjbCommodity);
        PageInfo<RjbCommodity> pageInfo = new PageInfo<>(rjbAdmins);
        return pageInfo;
    }

    @Override
    public List<RjbCommodity> likeAll(String name, int status) {
        return rjbCommodityDao.likeAll(name, status);
    }

    @Override
    public RjbCommodity insert(RjbCommodity rjbCommodity) {
        int i = this.rjbCommodityDao.insert(rjbCommodity);
        if (i > 0) return rjbCommodity;
        return new RjbCommodity();
    }

    @Override
    public RjbCommodity update(RjbCommodity rjbCommodity) {
        int i = this.rjbCommodityDao.update(rjbCommodity);
        if (i > 0) {
            return this.queryById(rjbCommodity.getMId());
        }
        return new RjbCommodity();
    }

    @Override
    public boolean deleteById(Integer mId) {
        return this.rjbCommodityDao.deleteById(mId) > 0;
    }

    @Override
    public List<RjbCommodity> fruit_list(Integer cid) {
        return rjbCommodityDao.fruitList(cid);
    }

    @Override
    public List<RjbCommodity> fruitStatus(int status) {
        return rjbCommodityDao.fruitStatus(status);
    }

    @Override
    public boolean deleteByIdOne(Integer mId) {
        RjbCommodity rjbCommodity = this.queryById(mId);
        rjbCommodity.setMStatus(-2); //逻辑删除
        RjbCommodity updateRjbCommodity = this.update(rjbCommodity);
        return updateRjbCommodity == null;
    }

    @Override
    public List<RjbCommodity> selectAllFruit() {
        return this.rjbCommodityDao.selectAllFruit();
    }

    @Override
    public List<RjbCommodity> selectAllFlower() {
        return this.rjbCommodityDao.selectAllFlower();
    }

    @Override
    public List<RjbCommodity> selectLimit(Integer page, Integer limit) {
        return this.rjbCommodityDao.selectLimit(page, limit);
    }

    @Override
    public int selectFruitNum() {
        return this.rjbCommodityDao.selectFruitNum();
    }

    @Override
    public List<RjbCommodity> selectLimitFlower(Integer page, Integer limit) {
        return this.rjbCommodityDao.selectLimitFlower(page, limit);
    }

    @Override
    public int selectFlowerNum() {
        return this.rjbCommodityDao.selectFlowerNum();
    }
}
